(function() {
	var o = 0;
	var d = document.getElementById("form_init_script").getAttribute(
			"data-name");
	var j = d + "common/libs_js/jquery-1.4.4.min.js";
	var b;
	var e = false;
	var h = [ d + "common/libs_js/jquery-ui-1.8.9.custom.min.js",
			d + "common/libs_js/jquery.ui.datepicker.js",
			d + "common/libs_js/easyXDM/easyXDM.min.js",
			d + "common/js/jquery.validate.js",
			d + "common/libs_js/jquery.metadata.js",
			d + "common/libs_js/jquery.placeholder.min.js",
			d + "validation_data.js?" + Math.floor(Math.random() * 1001),
			d + "common/js/validation.js", d + "common/js/conditionals.js",
			d + "common/libs_js/jquery.signaturepad.min.js" ];
	if (navigator.appName == "Microsoft Internet Explorer") {
		h.splice(0, 0, d + "common/libs_js/json2.js")
	}
	var m = [ d + "common/css/jquery-ui-1.8.5.custom.css",
			d + "common/css/normalize.css",
			d + "common/css/jquery.signaturepad.css" ];
	var a = function() {
		$.noConflict();
		b = jQuery;
		b(document).ready(function() {
			for ( var s = 0; s < h.length; s++) {
				c(h[s], p)
			}
		});
		(b).fb_resize = function() {
			if (b("#docContainer").attr("data-colorbox")) {
				return
			}
			if (window.parent && window.parent.pSockets) {
				window.parent.pSockets.refresh_height()
			} else {
				if (window.parent && window.parent.document
						&& window.parent.document.getElementById("fb_iframe")) {
					if (!e) {
						b(window.parent)
								.resize(
										function(i) {
											window.parent.document
													.getElementById("fb_iframe").height = b(
													"#docContainer")
													.outerHeight(true) + 30
										});
						e = true
					}
					window.parent.document.getElementById("fb_iframe").height = b(
							"#docContainer").outerHeight(true) + 30
				}
			}
		}
	};
	var p = function() {
		if (o < h.length - 1) {
			o++;
			return
		} else {
			q()
		}
	};
	function n() {
		b.each(b("#docContainer img"), function(u, t) {
			var v = b(t).attr("src");
			var i = v.search("common");
			if (i == -1) {
				i = v.search("theme")
			}
			var s = v.substr(0, i);
			v = v.replace(s, "");
			b(t).attr("src", v)
		});
		b.each(b("#docContainer, #docContainer *"), function(v, u) {
			if (u.style.backgroundImage) {
				var s = b(u).css("background-image");
				var w = s.search("http");
				if (w == -1) {
					w = s.search("file")
				}
				var i = s.search("common");
				if (i == -1) {
					i = s.search("theme")
				}
				if (w >= 0) {
					var t = s.substr(w, i - w);
					s = s.replace(t, "")
				}
				b(u).css("background-image", s)
			}
		})
	}
	function g() {
		jQuery.validator.addMethod("phoneUS", function(i, s) {
			i = i.replace(/[ext]{1,3}\.?\s*[\d]+$/, "");
			i = i.replace(/\s+/g, "");
			return this.optional(s) || i.match(/^\(\d{3}\)\d{3}-\d{4}$/)
					|| i.match(/^1-[\d-]{10}$/) || i.match(/^[\d-.]{10}$/)
		}, "Please specify a valid phone number");
		jQuery.validator.addMethod("phoneUK", function(i, s) {
			i = i.replace(/[ext]{1,3}\.?\s*[\d]+$/, "");
			i = i.replace(/\s+/g, "");
			return this.optional(s) || i.match(/^\(0\d{2}\)\d{8}$/)
					|| i.match(/^\(0\d{3}\)\d{7}$/)
					|| i.match(/^\(0\d{4}\)\d{5,6}$/)
					|| i.match(/^\(0\d{5}\)\d{4,5}$/) || i.match(/^0\d{9,10}$/)
		}, "Please specify a valid phone number");
		jQuery.validator.addMethod("mobileUK", function(i, s) {
			i = i.replace(/[ext]{1,3}\.?\s*[\d]+$/, "");
			i = i.replace(/\s+/g, "");
			return this.optional(s) || i.match(/^07\d{9}$/)
		}, "Please specify a valid mobile number");
		jQuery.validator.addMethod("international", function(i, s) {
			i = i.replace(/[ext]{1,3}\.?\s*[\d]+$/, "");
			i = i.replace(/\s+/g, "");
			i = i.replace(/[^\d+]/g, "");
			return this.optional(s) || i.match(/^\+?\d{9,15}$/)
		}, "Please enter a valid phone number");
		jQuery.validator.addMethod("regex_config", function(v, i, w) {
			try {
				var u = /^(\W)([^\1]+)\1(.*)$/.exec(w);
				var s = new RegExp(u[2], u[3]);
				return this.optional(i) || s.test(v)
			} catch (t) {
				return false
			}
		}, "Please enter a value matching the regular expression");
		jQuery.validator.addMethod("decimals", function(v, s, w) {
			try {
				var i = w;
				if (i == "zero") {
					i = 0
				}
				var t = new RegExp("^-?\\d+\\.?\\d{0," + i + "}?$");
				return this.optional(s) || t.test(v)
			} catch (u) {
				return false
			}
		}, "Please enter a valid number.");
		jQuery.validator.addMethod("minlength_checkbox", function(t, i, u) {
			try {
				return this.optional(i)
						|| this.getLength(jQuery.trim(t), i) >= u
			} catch (s) {
				return false
			}
		}, "Please select at least {0} options.")
	}
	function l() {
		var s = [];
		var w = [];
		if (data_jsplugins != undefined && data_jsplugins.length > 0) {
			s = JSON.parse(data_jsplugins)
		}
		if (data_cssplugins != undefined && data_cssplugins.length > 0) {
			w = JSON.parse(data_cssplugins)
		}
		for ( var v = 0; v < s.length; v++) {
			var t = s[v];
			if ("https:" == document.location.protocol
					&& t.substr(0, 5) != "https") {
				t = t.replace("http", "https")
			}
			c(t)
		}
		for ( var v = 0; v < w.length; v++) {
			var u = w[v];
			if ("https:" == document.location.protocol
					&& u.substr(0, 5) != "https") {
				u = u.replace("http", "https")
			}
			r(u)
		}
	}
	function k() {
		b("#fb_paypalwps, #fb_authnet, #fb_2checkout").click(function() {
			b.ajax( {
				url : "",
				data : {
					action : "submitpayment",
					gateway : this.id
				},
				async : false
			})
		})
	}
	function q() {
		if ((document.getElementById("docContainer") == null)
				|| (document.getElementById("docContainer").tagName
						.toLowerCase() != "form")
				|| b("#docContainer").attr("action") == undefined) {
			l();
			k();
			b.fb_resize();
			return
		}
		var x = document.getElementById("fb_js_enable");
		if (x != null && x != undefined) {
			x.setAttribute("value", "1")
		}
		b("#docContainer .column").contents().filter(function() {
			return this.nodeType === 3
		}).remove();
		g();
		var t = document.getElementById("docContainer").getAttribute(
				"data-form") == "preview";
		b.each(b("input[type=date]"), function(A, z) {
			var y = b(z).wrap("<div></div>").parent().html().replace(
					'type="date"', 'type="text"');
			b(z).replaceWith(y)
		});
		var w = new ValidateClient(b);
		w.init_client(t);
		var u = new ConditionalClient(b);
		u.init_client();
		if (b("#docContainer").attr("data-colorbox") != "true") {
			if (b('input[name="fb_form_custom_html"]').length
					&& b("#docContainer").attr("data-form") == "automated"
					&& b("#docContainer").attr("action") != "./") {
				b('input[name="fb_form_custom_html"]').get(0).value = parent.location.href
			}
			if (b('input[name="fb_form_embedded"]').length
					&& parent.frames.length != 0
					&& b("#docContainer").attr("data-form") == "publish") {
				b('input[name="fb_form_embedded"]').get(0).value = "1"
			}
			if (b('input[name="fb_url_embedded"]').length
					&& parent.frames.length != 0 && !window.parent.pSockets) {
				b('input[name="fb_url_embedded"]').get(0).value = encodeURIComponent(parent.location.href
						.split("?")[0])
			} else {
				if (b('input[name="fb_url_embedded"]').length
						&& parent.frames.length != 0 && window.parent.pSockets) {
					window.parent.pSockets
							.get_location(function(y) {
								b('input[name="fb_url_embedded"]').get(0).value = encodeURIComponent(y)
							})
				} else {
					if (b('input[name="fb_url_embedded"]').length
							&& b("#docContainer").attr("data-form") == "automated") {
						b('input[name="fb_url_embedded"]').get(0).value = $(
								"#docContainer").attr("action")
					} else {
						if (b('input[name="fb_url_embedded"]').length) {
							b('input[name="fb_url_embedded"]').get(0).value = encodeURIComponent(window.location.href
									.split("?")[0])
						}
					}
				}
			}
		}
		if (b('input[name="fb_url_embedded"]').length
				&& parent.frames.length != 0 && !window.parent.pSockets) {
			b('input[name="fb_url_embedded"]').get(0).value = encodeURIComponent(parent.location.href
					.split("?")[0])
		} else {
			if (b('input[name="fb_url_embedded"]').length
					&& parent.frames.length != 0 && window.parent.pSockets) {
				window.parent.pSockets
						.get_location(function(y) {
							b('input[name="fb_url_embedded"]').get(0).value = encodeURIComponent(y)
						})
			} else {
				if (b('input[name="fb_url_embedded"]').length
						&& b("#docContainer").attr("data-form") == "automated") {
					b('input[name="fb_url_embedded"]').get(0).value = $(
							"#docContainer").attr("action")
				} else {
					if (b('input[name="fb_url_embedded"]').length) {
						b('input[name="fb_url_embedded"]').get(0).value = encodeURIComponent(window.location.href
								.split("?")[0])
					}
				}
			}
		}
		if (b("#docContainer").attr("data-form") == "automated"
				&& (b("#docContainer").attr("action") == document.location.href || parent.frames.length != 0)) {
			n()
		}
		if ((b("#docContainer").attr("data-form") == "publish" || b(
				"#docContainer").attr("data-form") == "automated")
				&& parent.frames.length != 0
				|| b("#docContainer").attr("action").indexOf("http") != -1
				|| b("#docContainer").attr("action") == "./") {
			b(
					'#docContainer input[type!="submit"],#docContainer select,#docContainer textarea')
					.change(
							function(y) {
								b(
										'#docContainer input[type!="submit"],#docContainer select,#docContainer textarea')
										.unbind(y);
								var z = b("#docContainer").attr("action");
								z = z.replace(/(?:\.php)|\/$/i,
										"/fbapp/api/formchangestats.php");
								b.get(z);
								b.fb_resize()
							})
		}
		b(
				"#docContainer .fb-checkbox, #docContainer .fb-radio, #docContainer .fb-dropdown, #docContainer .fb-listbox")
				.parent().mouseleave(function() {
					var y = b(".showing_hint", this);
					if (y != undefined) {
						y.removeClass("showing_hint").addClass("hidden_hint")
					}
				});
		b("#docContainer input:file").parent().parent().mouseleave(function() {
			var y = b(".showing_hint", this);
			if (y != undefined) {
				y.removeClass("showing_hint").addClass("hidden_hint")
			}
		});
		b("#docContainer input:checkbox, #docContainer input:radio").blur(
				function() {
					var y = b(".showing_hint", b(this).parent().parent()
							.parent());
					if (y != undefined) {
						y.removeClass("showing_hint").addClass("hidden_hint")
					}
				});
		b(
				"#docContainer .column select, #docContainer .column input, #docContainer .column textarea")
				.blur(function() {
					var y = b(".showing_hint", b(this).parent().parent());
					if (y != undefined) {
						y.removeClass("showing_hint").addClass("hidden_hint")
					}
				});
		b(
				"#docContainer .fb-checkbox, #docContainer .fb-radio, #docContainer .fb-dropdown, #docContainer .fb-listbox")
				.parent().mouseenter(function() {
					var y = b(".hidden_hint", this);
					if (y != undefined) {
						y.removeClass("hidden_hint").addClass("showing_hint")
					}
				});
		b("#docContainer input:file").parent().parent().mouseenter(function() {
			var y = b(".hidden_hint", this);
			if (y != undefined) {
				y.removeClass("hidden_hint").addClass("showing_hint")
			}
		});
		b("#docContainer input:checkbox, #docContainer input:radio").focus(
				function() {
					var y = b(".hidden_hint", b(this).parent().parent()
							.parent());
					if (y != undefined) {
						y.removeClass("hidden_hint").addClass("showing_hint")
					}
				});
		b(
				"#docContainer .column select, #docContainer .column input, #docContainer .column textarea")
				.focus(function() {
					var y = b(".hidden_hint", b(this).parent().parent());
					if (y != undefined) {
						y.removeClass("hidden_hint").addClass("showing_hint")
					}
				});
		b("input:file").change(function() {
			b("#docContainer").validate().element(this)
		});
		b("input[type=url]").blur(function() {
			b("#docContainer").validate().element(this)
		});
		b("input[type=email]").blur(function() {
			b("#docContainer").validate().element(this)
		});
		b("input[type=password]").blur(function() {
			b("#docContainer").validate().element(this)
		});
		b("input[type=tel]").blur(function() {
			b("#docContainer").validate().element(this)
		});
		if (navigator.appName == "Microsoft Internet Explorer") {
			b("input[type=tel]").keyup(function() {
				return false
			});
			var s = parseFloat(navigator.appVersion.split("MSIE")[1]);
			if (s < 9) {
				b("#docContainer select").each(
						function() {
							var y = true;
							b(this).mousedown(
									function() {
										if (y) {
											var A = parseInt(b(this).css(
													"width"));
											var z = parseInt(b(this).css(
													"width", "auto").css(
													"width"));
											if (A > z) {
												b(this).css("width", "")
											}
										}
										y = false
									}).blur(function() {
								b(this).css("width", "");
								y = true
							}).change(function() {
								b(this).css("width", "");
								y = true
							})
						})
			}
		}
		b("input[type=number]").keyup(
				function() {
					var y = b("#docContainer").validate().element(this);
					if (navigator.appName != "Microsoft Internet Explorer"
							&& b("#" + this.id + ":invalid").length > 0
							&& (y == undefined || y == true)) {
						var A = this.name;
						var z = {};
						z[A] = "Input must be a valid number";
						b("#docContainer").validate().showErrors(z)
					} else {
						b('label[for="' + this.id + '"]').remove();
						b("#docContainer").validate().element(this)
					}
				}).blur(function() {
			b('label[for="' + this.id + '"]').remove();
			b("#docContainer").validate().element(this)
		});
		var v = "placeholder" in document.createElement("input");
		var i = "placeholder" in document.createElement("textarea");
		if (!v) {
			b("#docContainer input").not('[type="password"]').placeholder()
		}
		if (!i) {
			b("#docContainer textarea").placeholder()
		}
		l();
		c(d + "common/js/lang/messages_validation.js");
		c(d + "common/js/lang/messages_datepicker.js");
		b(document).ready(function() {
			setTimeout(b.fb_resize, 1000)
		})
	}
	var c = function(i, t) {
		var s = document.createElement("script");
		s.setAttribute("type", "text/javascript");
		s.setAttribute("src", i);
		if (t != undefined) {
			if (s.addEventListener) {
				s.addEventListener("load", t, false)
			} else {
				if (s.attachEvent) {
					s.attachEvent("onreadystatechange", function() {
						if (s.readyState == "complete"
								|| s.readyState == "loaded") {
							t()
						}
					})
				}
			}
		}
		document.getElementsByTagName("head")[0].appendChild(s)
	};
	var r = function(i) {
		var s = document.createElement("link");
		s.setAttribute("rel", "stylesheet");
		s.setAttribute("type", "text/css");
		s.setAttribute("href", i);
		document.getElementsByTagName("head")[0].appendChild(s)
	};
	for ( var f = 0; f < m.length; f++) {
		r(m[f])
	}
	c(j, a)
})();